package com.kx.yooli.kx.wechat.utils.log;

import com.alibaba.fastjson2.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * @author john_sqwen-childe.wen
 * date 2024/4/8
 * PROJECT_NAME wechat
 * description create ExceptionLog by john_sqwen
 * and  value is
 */
public class ExceptionLog extends LogBean{
    private final Logger log = LoggerFactory.getLogger(ExceptionLog.class);
    private static final String LABEL = "exception";

    private ExceptionLog(Exception e, String otherInfo) {
        super((String)null, (String)null, (Object)null, (String)null, (String)null, (Object)null);
        this.setLabel("exception");
        String tempInfo = "";
        String fileNameAndLineNumber = "";
        int index = 2;
        Map<String, String> parms = new HashMap(e.getStackTrace().length + 2);
        parms.put("0", otherInfo);
        parms.put("1", e.toString());
        StackTraceElement[] var10;
        int var9 = (var10 = e.getStackTrace()).length;

        for(int var8 = 0; var8 < var9; ++var8) {
            StackTraceElement temp = var10[var8];
            if (temp.getFileName() == null) {
                fileNameAndLineNumber = "Unknown Source";
            } else {
                fileNameAndLineNumber = temp.getFileName() + ":" + temp.getLineNumber();
            }

            tempInfo = "at " + temp.getClassName() + "." + temp.getMethodName() + "(" + fileNameAndLineNumber + ")";
            parms.put(String.valueOf(index), tempInfo);
            ++index;
        }

        this.setParams(parms);
    }

    public static ExceptionLog create(Exception e, String otherInfo) {
        return new ExceptionLog(e, otherInfo);
    }

    public String toString() {
        return JSONObject.toJSONString(this);
    }
}
